home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1846 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: fang.dsto.defence.gov.au!usenet
  2. From: dpr@itd.dsto.gov.au (David Rajaratnam)
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: 'interrupt' in Turbo C++
  5. Date: 12 Jan 1996 04:45:22 GMT
  6. Organization: Defence Science & Technology Organisation
  7. Distribution: world
  8. Message-ID: <4d4p12$67h@fang.dsto.defence.gov.au>
  9. Reply-To: dpr@itd.dsto.gov.au
  10. NNTP-Posting-Host: tcs17.dsto.gov.au
  11.  
  12.  
  13. Hi there,
  14. I hope I've got the right newsgroups for this question. 
  15. I'm having problems writing an interrupt handler using 
  16. Borland Turbo C++ v3 for DOS. The problem arises when 
  17. I want the interrupt function to return results via 
  18. the registers.
  19.  
  20. Under C what I do is;
  21.  
  22. typedef struct {
  23.     int bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, fl;
  24. } IREGS;
  25.  
  26. static void interrupt (*mycinterrupt)(IREGS ir){
  27.     
  28.     <do stuff>
  29.     
  30.     ir.ax = _AX
  31. }
  32.  
  33. I don't know how this works, but it does. Normally if you pass a value
  34. in the argument list changing it is doesn't pass back the original
  35. value - that's what pointers are for! However I presume this is 
  36. a messy (counter intuitive) workaround to allow register values
  37. to be changed, since declaring a function as 'interrupt' should 
  38. save and restore ALL registers on return so what ever values 
  39. saved to registers inside the function are lost.
  40.  
  41. Unfortunately, the declaration of setvect and getvect in C++ 
  42. does things a bit differently. I quote;
  43.  
  44.   Syntax
  45.   void interrupt(*getvect(int interruptno))();                 /*C version*/
  46.   void interrupt(*getvect(int interruptno))(...);            //C++ version
  47.   void setvect(int interruptno, void interrupt (*isr)());    /*C version*/
  48.   void setvect(int interruptno, void interrupt (*isr)(...)); //C++ version
  49.  
  50. So making the call setvect(0xXX, mycinterrupt) will give me a 
  51. compiler error now. To get around this what I tried to do was;
  52.  
  53. static void interrupt (*mycppinterrupt)(...){
  54.     IREGS *ir;
  55.  
  56.     <do stuff>
  57.  
  58.     ir = (IREGS *)...;
  59.     ir->ax = _AX;
  60. }
  61.  
  62. Although this version compilied, when run the results where 
  63. not what I was hoping for. I also tried using the <stdarg.h>
  64. stuff but they gave me the same results as above. I can only
  65. guess that what C++ expects to see is different to the
  66. C version. Unfortunately nowhere in the Documentation (that
  67. I can find), or other books I own, does it describe what 
  68. C++ expects. Mind you the arguments of the C version were
  69. not adequately described either, it's just that I happened
  70. to come across an example that used the 
  71. tydef struct { bp, ...} IREGS method.  
  72.  
  73.  
  74. If anyone could provide a solution or a pointer to books that
  75. might be useful I would greatly appreciate it. (An explanation
  76. of what C does as well, in terms of argument lists, when a 
  77. function is declared as 'interrupt' would also be handy)
  78.  
  79. Thanks in advance,
  80.  
  81. Dave Rajaratnam
  82.  
  83.  
  84.